Skip to content

Proof of concept for running a PHP script without Docker - #9164

Merged
caleeli merged 11 commits into
feature/FOUR-34328from
task/scriptrunner
Nov 13, 2026
Merged

caleeli merged 11 commits into
feature/FOUR-34328from
task/scriptrunner

Conversation

@marcoAntonioNina

Copy link
Copy Markdown
Contributor

Added per-script execution modes with bare as the default and optional modules execution for trusted PHP scripts. Added migration, resolver, permissions, UI selection, module gating, and test coverage while preserving Docker/microservice execution and legacy $result scripts.

variables .env

scripts

CORE_SERVICE_TASK_ENABLED=true
CORE_SERVICE_TASK_MODULES_ENABLED=true
CORE_SERVICE_TASK_EXECUTION=bare

… mode to scripts. Introduced `hasExplicitReturn` method to determine return statements in scripts. Updated core service task configuration to set default execution mode to 'bare' and added migration for `execution_mode` column in scripts and script_versions tables. Expanded PermissionSeeder to include 'run-in-process-modules' permission. Added unit tests for legacy result variable and explicit scalar return handling in ScriptRuntime.
…cks. Implemented `authorizeModulesExecution` method in `ScriptController` to manage execution modes. Updated `Script` model to include `execution_mode` property and validation rules. Introduced `ScriptExecutionModeResolver` service for determining execution modes. Enhanced UI to allow selection of execution mode in script editing. Added tests for execution mode functionality and authorization checks.
@cursor

cursor Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes default in-process execution to bare and alters script runtime, import, and permission checks; misconfiguration could affect how trusted PHP scripts run in production.

Overview
This PR adds per-script execution_mode (bare vs modules) for trusted in-process PHP scripts, with bare as the default and migration on scripts / script_versions.

Resolver and runtime: ScriptExecutionModeResolver picks the effective mode from allow_in_process, the script field, CORE_SERVICE_TASK_EXECUTION, and the new modules_enabled gate (default off; global default execution is now bare). In-process paths (ScriptRunner, CoreServiceTask, TestScript) use the resolver instead of a single global execution flag. ScriptRuntime keeps legacy scripts that set $result without a top-level return, while honoring explicit scalar/null returns.

Authorization and import: New run-in-process-modules permission; APIs and import copy downgrade to bare when the actor lacks admin or that permission. Import Options now carry importingUserId so ScriptExporter can apply the same rules.

UI: Script edit screen exposes execution mode when modules are enabled and the user is allowed.

Tests cover API fallbacks, import behavior, resolver rules, and runtime return semantics.

Reviewed by Cursor Bugbot for commit 963bc36. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread ProcessMaker/Models/Script.php Resolved
Comment thread ProcessMaker/Jobs/TestScript.php Resolved
@cursor
cursor Bot requested review from gusys and nolanpro November 12, 2026 18:29
…roduced `canUseModules` method for streamlined permission validation in `ScriptController`, `ScriptExporter`, and `TestScript`. Updated tests to ensure non-privileged users fall back to bare execution mode when duplicating or editing scripts. Enhanced `ScriptRuntime` to handle nested return statements correctly.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

return Script::EXECUTION_MODE_BARE;
}

$mode = $script->execution_mode ?: config('core-service-task.execution', Script::EXECUTION_MODE_BARE);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: HIGH

Description: A process import can persist a falsy script execution_mode (empty string or "0") with allow_in_process true. ScriptExecutionModeResolver treats that falsy value as config('core-service-task.execution'). When that setting is modules and modules_enabled is on, ScriptRunner and CoreServiceTask include the package PHP inside the Laravel worker. The new run-in-process-modules check only recognizes the exact string modules, so an importer who lacks that permission and is not an administrator still reaches worker execution.

Impact: This bypasses the permission this PR adds around trusted in-worker PHP. A user who only has import-processes can store attacker-controlled PHP that later runs in the application worker, with registered ScriptRuntime modules, the worker's privileges, every EnvironmentVariable copied into the process environment, and an API token for the script run-as user. That is full control of the app process. It matters only when CORE_SERVICE_TASK_ENABLED, CORE_SERVICE_TASK_MODULES_ENABLED, and CORE_SERVICE_TASK_EXECUTION=modules are set. The execution default is bare, and per-script modules already works without that env var, but execution=modules is a documented mode and the resolver uses it as the fallback. The script runs when the imported process is started (start is a separate process-policy check the package can satisfy); import itself does not launch it. Preview is unaffected: TestScript forces bare when the current user lacks run-in-process-modules.

Remediation: In ScriptExecutionModeResolver, treat only the exact string modules as modules. Map null, empty string, "0", and every other value to bare, and do not consult core-service-task.execution for that decision. In ScriptExporter::import, set execution_mode to bare unless the value is exactly modules and canUseModules() is true. Apply that normalization before the first Importer save.

…mportController and ImportV2. Refactor ScriptExporter to utilize the importing user ID for permission checks. Update execution mode handling in ScriptController to default to bare mode. Add tests for import behavior based on user authorization and execution mode preservation. Improve ScriptRuntime to handle nested curly braces correctly.
cursor[bot]

This comment was marked as resolved.

…Extracted logic for handling tokens and brace management into dedicated methods. Updated unit tests to reflect changes in helper function syntax.
…property to facilitate permission checks in API tests, ensuring proper authorization during script execution tests.
@decisions-sonarqube

Copy link
Copy Markdown

@caleeli
caleeli merged commit b14ebf5 into feature/FOUR-34328 Nov 13, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants